package com.hpu.service;

import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;

import com.hpu.callback.ShareDownloadCallback;
import com.hpu.constants.HttpConstants;
import com.hpu.constants.ShareConstants;
import com.hpu.constants.UrlConstants;
import com.hpu.interceptor.ReceivedCookieInterceptor;
import com.hpu.tools.InternetTools;
import com.hpu.tools.OkHttpTools;
import com.hpu.tools.ShareTools;

/**
 * 最新公告业务类，获取40条最新公告的标题与id
 * @author Administrator
 *
 */
public class ShareDownloadService{

	private Handler handler;
	
	private Context context;
	
	public ShareDownloadService(Handler handler,Context context) {
		this.handler=handler;
		this.context=context;
	}
	
	public void doShareDownload(String id) {
		if(TextUtils.isEmpty(id)){
			handler.sendEmptyMessage(HttpConstants.SHARE_COURSE_DOWNLOAD_FAIL);
		}
		else if(InternetTools.statusInternet(context)==InternetTools.NO_INTERNET)
			handler.sendEmptyMessage(HttpConstants.NO_INTERNET);
		else
		OkHttpTools.postByCookie(new ReceivedCookieInterceptor(context),UrlConstants.INTERFACE_DOWNLOAD_SHARECOURSE,
				ShareTools.get(context, ShareConstants.STORE_LOGINCOOKIE, "").toString(),
				new ShareDownloadCallback(handler),
				new String[]{"share_id"},
				new String[]{id});
	}

}

